home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18432 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  84 lines

  1. Path: news.win.tue.nl!not-for-mail
  2. From: joepdv@wsooti21.win.tue.nl (Joep de Vocht)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP: what goes wrong here?
  5. Date: 20 Apr 1996 15:43:09 +0200
  6. Organization: Eindhoven University of Technology, The Netherlands
  7. Message-ID: <4lapld$1q4@wsooti21.win.tue.nl>
  8. NNTP-Posting-Host: wsooti21.win.tue.nl
  9. Summary: HELP: I can't get this simple program to compile
  10. Keywords: HELP
  11.  
  12. This question is probably very easy to solve.
  13. However, the program given below won't compile and
  14. I can't figure out why.
  15. Maybe you can help a C++ novice.
  16.  
  17. The two compiler errors given by the turbo c++ compiler are
  18. included in the code. If you have any other remarks about
  19. the code (weird constructions or anything) please state them.
  20.  
  21. Greetings,
  22.  
  23. Joep.
  24.  
  25. ------------ main program ------------
  26. #include "x.h"
  27. #include "base.h"
  28. #include "derived.h"
  29.  
  30. int main()
  31. {
  32.   derived d() ;
  33.   d.execute() ;
  34.   return 0 ;
  35. }
  36.  
  37. ------------ X.h ---------------------
  38. class X
  39. {
  40.   private:
  41.     int n ;
  42.   public:
  43.     X(int i) {n=i ;}
  44.     void do_someting() ;
  45. } ;
  46.  
  47. ------------ X.cpp -------------------
  48. #include "x.h"
  49.  
  50. void X::do_someting() {n++ ;}
  51.  
  52. ------------ base.h ------------------
  53. class base
  54. {
  55.   protected:
  56.     static X x ;  COMPILER ERROR: ", exspected"
  57.   public:
  58.     base() ;
  59.     virtual void execute() =0 ;
  60. } ;
  61.  
  62. ------------ base.cpp ----------------
  63. #include "base.h"
  64.  
  65. base::base() { x(10) ;} ; COMPILER ERROR: "call of non-function"
  66.  
  67. ------------ derived.h ---------------
  68. class derived: public base
  69. {
  70.   public:
  71.     derived() ;
  72.     void execute(int) ;
  73. } ;
  74.  
  75. ------------ derived.cpp -------------
  76. #include "derived.h"
  77.  
  78. derived::derived():base() ;
  79. void derived::execute() { x.do_something() ;}
  80.  
  81.  
  82.  
  83.  
  84.